package com.zretc.demojparedis.controller;


import com.zretc.demojparedis.commons.LoginBean;
import com.zretc.demojparedis.commons.PageData;
import com.zretc.demojparedis.commons.RetryOnOptimisticLockingFailure;
import com.zretc.demojparedis.dao.AuthRedis;
import com.zretc.demojparedis.entity.Question;
import com.zretc.demojparedis.entity.Users;
import com.zretc.demojparedis.service.QuestionService;
import com.zretc.demojparedis.service.UsersService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;
import java.util.Random;
import java.util.UUID;

@RestController
@RequestMapping("usersapi")
public class UsersController {

    //创建一个日志记录对象
    Logger logger = LoggerFactory.getLogger(UsersController.class);

    @Autowired
    private UsersService usersService;


    @GetMapping("userlogin")
    @ApiOperation(value = "登录",notes = "登录请求")
    public LoginBean login(@RequestParam("userName") String userName, @RequestParam("userPwd") String userPwd) {
        logger.info("userName:"+userName);
        return usersService.getUsersByNameAndPwd(userName,userPwd);
    }

    @GetMapping("/logout")
    public String logout(HttpServletRequest request) {
        String token = request.getHeader("token");
        return usersService.logout(token);
    }





}
